# 代码基本为原创，虽然还有点bug
import sys


def check_input():
    return1 = input("请输入一串字符：")
    if 0 < len(return1) < 255:
        print("输入合法,字符串长度在(0~255)之间！")
        return return1
    else:
        print("输入不合法")
        sys.exit()


def letter(a):
    input2 = filter(str.isalpha, a)
    str1 = str(''.join(list(input2)))
    print("剔除非英文后为：" + str1)
    return str1


def reverse(c):
    print("剔除反转后为：" + c[::-1])
    return c[::-1]


def enCode(a):
    c = list(a)
    x = len(c)
    for i in range(x):
        if ord('A') <= ord(a[i]) <= ord('Z'):
            c[i] = chr((ord(c[i]) + 3 - ord('A')) % 26 + ord('A'))
        elif ord('a') <= ord(a[i]) <= ord('z'):
            c[i] = chr((ord(c[i]) + 3 - ord('a')) % 26 + ord('a'))
        else:
            c[i] = chr(ord(c[i]))
    mi = ''.join(c)
    print("再凯撒加密后为：" + mi)


def main():
    input2 = check_input()
    result2 = letter(input2)
    result3 = reverse(result2)
    enCode(result3)


main()
